<?php
include("function.php");
mssql_select_db($mssql_database, $conn);
$b=$_GET['id'];
global $s ;
global $e ;
global $p ;
global $batch ;
$batch=(int)$b;//数据类型强制转换成int
$s=$_COOKIE["s"];
$e=$_COOKIE["e"];
$p=$_COOKIE["p"];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>对账系统</title>
<meta name="Copyright" content="Douco Design." />
<link href="css/public.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/global.js"></script>
<script language="javascript" type="text/javascript" src="js/My97DatePicker/WdatePicker.js"></script>
<script language="javascript" src="js/LodopFuncs.js"></script>
<object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> 
	<embed id="LODOP_EM" TYPE="application/x-print-lodop" width=0 height=0 PLUGINSPAGE="install_lodop.exe"></embed>
</object> 
<style type="text/css">
.demo a:link {color: #FF0000} /* 未访问的链接 */
.demo a:visited {color: #FF0000} /* 已访问的链接 */
.demo a:hover {color: #FF00FF} /* 鼠标移动到链接上 */
.demo a:active {color: #0000FF} /* 选定的链接 */
p {
	margin: 0
}

#page {
	height: 40px;
	padding: 20px 0px;
}

#page a {
	display: block;
	float: left;
	margin-right: 10px;
	padding: 2px 12px;
	height: 24px;
	border: 1px #cccccc solid;
	background: #fff;
	text-decoration: none;
	color: #808080;
	font-size: 12px;
	line-height: 24px;
}

#page a:hover {
	color: #077ee3;
	border: 1px #077ee3 solid;
}

#page a.cur {
	border: none;
	background: #077ee3;
	color: #fff;
}

#page p {
	float: left;
	padding: 2px 12px;
	font-size: 12px;
	height: 24px;
	line-height: 24px;
	color: #bbb;
	border: 1px #ccc solid;
	background: #fcfcfc;
	margin-right: 8px;
}

#page p.pageRemark {
	border-style: none;
	background: none;
	margin-right: 0px;
	padding: 4px 0px;
	color: #666;
}

#page p.pageRemark b {
	color: red;
}

#page p.pageEllipsis {
	border-style: none;
	background: none;
	padding: 4px 0px;
	color: #808080;
}

.dates li {
	font-size: 14px;
	margin: 20px 0
}

.dates li span {
	float: right
}
</style>
 <?php
include('page.class.php'); //分页类
// error_reporting(0);
mssql_select_db($mssql_database, $conn);

$showrow = 100; //一页显示的行数
$curpage = empty($_GET['page']) ? 1 : $_GET['page']; //当前的页,还应该处理非数字的情况
$url = "?page={page}"; //分页地址，如果有检索条件 ="?page={page}&q=".$_GET['q']
//省略了链接mysql的代码，测试时自行添加
$sql = "SELECT * from dzxt where Date between '$s' and '$e' and etypeid='$p' and batch='$batch'";
$limit=($curpage - 1) * $showrow;
$total = mssql_num_rows(mssql_query($sql)); //记录总条数
if (!empty($_GET['page']) && $total != 0 && $curpage > ceil($total / $showrow))
    $curpage = ceil($total_rows / $showrow); //当前页数大于最后页数，取最后一页
//获取数据
// $sql2= "with fy
// as(
// select top $showrow Vchcode from dzxt  AS B where B.etypeid='$p' and B.Date between '$s' and '$e' and B.batch='$batch' and B.Vchcode not in(select top $limit Vchcode from dzxt where Date between '$s' and '$e' and etypeid='$p' and  batch='$batch' )
// )
// select *  from dzxt where Vchcode in (select * from fy) order by Number
// ";
$sql2= "with fy
as(
select top $showrow Vchcode from dzxt  AS B where B.etypeid='$p' and B.Date between '$s' and '$e' and B.batch='$batch' and B.Vchcode not in(select top $limit Vchcode from dzxt where Date between '$s' and '$e' and etypeid='$p' and batch='$batch' )
)
select *  from dzxt where Vchcode in (select * from fy) order by Number
";
//$sql2="select * from dzxt where etypeid='$p' and Date between '$s' and '$e' ";
$sq=iconv("utf-8",'gb2312',"$sql2");
$query = mssql_query($sq);
$sqle = "select etypeid,efullname from employee";
$qe=mssql_query($sqle);

$sqc="select SUM(cash) as cash from dzxt where etypeid='$p' and Date between '$s' and '$e' and batch='$batch' ";
$qc=mssql_query($sqc);
$sqy="select SUM(yh) as yh from dzxt where etypeid='$p' and Date between '$s' and '$e' and batch='$batch' ";
$qy=mssql_query($sqy);
$sqd="select SUM(debt) as debt from dzxt where etypeid='$p' and Date between '$s' and '$e' and batch='$batch' ";
$qd=mssql_query($sqd);
$i=1;
?>
</head>
<body>
<div id="dcWrap"> <div id="dcHead">
 <div id="head">
  <div class="logo"><a href="index.php"><img src="images/logo.png" alt="logo"></a></div>
  <div class="nav">
   <ul>
    <li class="noRight"><a href="index.php">业务草稿销售单&经营历程销售单</a></li>
   </ul>
   </div>
 </div>
</div>
<!-- dcHead 结束 --> <div id="dcLeft"><div id="menu">
				<ul class="top">
					<li ><a href="index.php"><i class="home"></i><em>单据分配</em></a></li>
				</ul>
				<ul>
					<li class="cur"><a href="jz.php"><i class="managerLog"></i><em>交账处理</em></a></li>
					<li><a href="exchange.php"><i class="backup"></i><em>送货更换</em></a></li>
					<li><a href="init.php"><i class="system"></i><em>报错点这里</em></a></li>
				</ul>
			</div></div>
 <div id="dcMain"> <!-- 当前位置 -->
<div id="urHere">单据管理中心</div>  <div id="index" class="mainBox" style="padding-top:18px;height:auto!important;height:550px;min-height:550px;">
      
    
   <div id="douApi"></div>
      <div class="indexBox">
    <div class="boxTitle">送货人交账</div>
    
   </div>
      <div class="filter">
    <form action="jzcl.php" method="post">
     <input name="start"  value="<?php echo $s;?>" type="text" class="inpMain"  onClick="WdatePicker()"/>
     ~
     <input name="end"  value="<?php echo $e;?>" type="text" class="inpMain"  onClick="WdatePicker()"/>
      <th >选择职员:</th>
								<td><select name="employee" id="" value="<?php echo $p;?>>
										 <?php while ( $rste = mssql_fetch_assoc ( $qe ) ) {
									     ?>
                                    <option value="<?php echo iconv ( 'gbk', 'utf-8', $rste [etypeid] ); ?>"
                                  <?php 
                                  if ($rste[etypeid] == $p) //设置select默认值为选中值
                                  {
                                  	?>selected="selected" <?php
                                     } ?>
                                    >
                                    <?php  
                                    
                                    echo iconv ( 'gbk', 'utf-8', $rste [efullname] ); ?></option>
                                                                  <?php
                                                                          }
																	?>
                                </select></td>
     <input name="submit" class="btnGray" type="submit" value="筛选" />
       </form>
       <div id="list" class="demo">
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
        <tr>
       <th width="10" align="center">当前查看批次为："<?php echo $batch;?>"</th>
       <?php 
       $sqlbatch="select distinct batch from dzxt where etypeid='$p'";
       $queryb = mssql_query($sqlbatch);
       while ($rstb = mssql_fetch_assoc ( $queryb )){
       	?>
       	<th width="5" align="center"><a href='jzp.php?id=<?php  echo $rstb['batch'];?>'><?php  echo $rstb['batch'];?> </th>
       	<?php
       }
       
       ?>
      
     </tr>
        </div>
      </div>
      
         </div>      
           
   <div class="clear"></div>
        <div id="list" class="demo">
        
      <div id='div1'>
    <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
     <tr>
       <th width="5" align="center">行号</th>
       <th width="5" align="center">批次</th>
       <th width="30" align="center">送货人</th>
       <th width="40" align="center">单据编号</th>
      <th width="40" align="center">往来单位</th>
      <th width="150" align="center">摘要</th>
      <th width="20" align="center">应收（元）</th>
      <th width="10" align="center">收款（元）</th>
      <th width="20" align="center">优惠（元）</th>
      <th width="10" align="center">欠账（元）</th>
      
     </tr>
    
                   <?php
																			while ( $rst = mssql_fetch_assoc ( $query ) ) {
																				?>
                   <tr>
					 <td align="center"><?php echo $i;$i++;?></td>
					  <td align="center"  type="number"  class="editbatch" id="<?php echo iconv ( 'gbk', 'utf-8', $rst ['Vchcode']); ?>"><?php echo round(iconv ( 'gbk', 'utf-8', $rst ['batch']),2); ?></td>
					  <td align="center"><?php 
					  global $shr;
					  $shr=iconv ( 'gbk', 'utf-8', $rst [efullname] );
					  echo $shr;
						 ?></td>
					 <td align="center"><?php echo $rst ['Number'];?></td>
						 <td align="center"><?php echo iconv ( 'gbk', 'utf-8', $rst ['bfullname']);
						 ?></td>
						  <td align="center"><?php echo iconv ( 'gbk', 'utf-8', $rst ['summary']); ?></td>
						  <td align="center" type="number"><?php echo round(iconv ( 'gbk', 'utf-8', $rst ['Total']),2); ?></td>
						  <td align="center"  type="number"  class="edit" id="<?php echo iconv ( 'gbk', 'utf-8', $rst ['Vchcode']); ?>"><?php echo round(iconv ( 'gbk', 'utf-8', $rst ['cash']),2); ?></td>
						  <td align="center"  type="number"  class="edityh" id="<?php echo iconv ( 'gbk', 'utf-8', $rst ['Vchcode']); ?>"><?php echo round(iconv ( 'gbk', 'utf-8', $rst ['yh']),2); ?></td>
						  <td align="center"  type="number"  id="debt"><?php echo round(iconv ( 'gbk', 'utf-8', $rst ['debt']),2); ?></td>
				          
					</tr>
                   
                     <?php
																			}
																			
																			?>
																			<th>合计</th>
          <th>第<?php echo $batch;?>批</th>
          <th><?php echo $shr;?></th>
          <th></th>
          <th></th>
          <th></th>
          <th> <?php
          $sqt="select SUM(Total) as total from dzxt where  batch='$batch' and etypeid='$p' and Date between '$s' and '$e' ";
          $qt=mssql_query($sqt);
         
           while ( $rstt = mssql_fetch_assoc ( $qt ) ) {
									    
                                    echo  round(iconv ( 'gbk', 'utf-8', $rstt ['total']),2);
          }?></th>
           <th> <?php while ( $rstc = mssql_fetch_assoc ( $qc ) ) {
									    
                                    echo  round(iconv ( 'gbk', 'utf-8', $rstc ['cash']),2);
          }?></th>
          <th><?php  while ( $rsty= mssql_fetch_assoc ( $qy) ) {
									    
                                    echo  round(iconv ( 'gbk', 'utf-8', $rsty ['yh']),2);
          }?>
            </th>
            <th><?php  while ( $rstd = mssql_fetch_assoc ( $qd ) ) {
									    
                                    echo  round(iconv ( 'gbk', 'utf-8', $rstd ['debt']),2);
          }?>
            </th>
          
   
      
      </table>
    </div>
 
    </div>
           <div class="showPage"> <?php
																				if ($total > $showrow) { // 总记录数大于每页显示数，显示分页
																					$page = new page ( $total, $showrow, $curpage, $url, 2 );
																					echo $page->myde_write ();
																				}
																				?>          </div>
    <div class="clear"></div>

 </div>
 <div class="clear"></div>
<div id="dcFooter">
 <div id="footer">
  <div class="line"></div>
 
  <ul>
   版权所有 © 2015-2018 jsycydym@qq.com，并保留所有权利。
  </ul>
 </div>
</div><!-- dcFooter 结束 -->
<div class="clear"></div> </div>
<script type="text/javascript" src="http://www.sucaihuo.com/Public/js/other/jquery.js"></script> 
        <script type="text/javascript" src="js/jquery.jeditable.min.js"></script>
        <script type='text/javascript' src='js/jquery-ui.min.js'></script>
		<script type="text/javascript">
            $(function() {
                $('.edit').editable('ajax.php', {
                    width: 20,
                    height: 18,
                    //onblur    : "ignore",
                    indicator: '<img src="images/loader.gif">',
                    tooltip: '单击填写...',
                    callback: function(value, settings) {
                        $("#modifiedtime").html("刚刚");
                    }
                });
                     $('.edityh').editable('ajaxyh.php', {
                    width: 20,
                    height: 18,
                    //onblur    : "ignore",
                    indicator: '<img src="images/loader.gif">',
                    tooltip: '单击填写...',
                    callback: function(value, settings) {
                        $("#modifiedtime").html("刚刚");
                    }
                });
                     $('.editbatch').editable('ajaxb.php', {
                         width: 20,
                         height: 18,
                         //onblur    : "ignore",
                         indicator: '<img src="images/loader.gif">',
                         tooltip: '单击填写...',
                         callback: function(value, settings) {
                             $("#modifiedtime").html("刚刚");
                         }
                     });
                $('.edit_select').editable('ajaxe.php', {
                    loadurl: 'json.php',
                    type: "select",
                    indicator: '<img src="images/loader.gif">',
                    tooltip: '单击选择.',
                    style: 'display: inline'
                });
                $(".datepicker").editable('ajax.php', {
                    width: 120,
                    type: 'datepicker',
                    onblur: "ignore",
                    indicator: '<img src="images/loader.gif">',
                    tooltip: '单击填写...',
                    style: 'display: inline'
                });
                $(".textarea").editable('ajax.php', {
                    type: 'textarea',
                    rows: 6,
                    cols: 50,
                    onblur: "ignore",
                    indicator: '<img src="images/loader.gif">'
                });
            });      
        </script>
<script language="javascript" type="text/javascript"> 
	var LODOP; //声明为全局变量  
	function SaveAsFile(){
		LODOP=getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));  
		LODOP.PRINT_INIT("");
		LODOP.ADD_PRINT_TABLE(100,20,500,80,document.documentElement.innerHTML);
		LODOP.SET_SAVE_MODE("QUICK_SAVE",true);//快速生成（无表格样式,数据量较大时或许用到）
		LODOP.SAVE_TO_FILE("<?php echo $shr.$e;?>.xls");
// 		运行错误91’ 未设置对象变量或 with block 变量 
// 		1. 打开注册表编辑器。（开始->运行->regedit）
// 		2. 找到[HKEY_CURRENT_USER--Software--Microsoft--Office--EXCEL--Addins]
// 		将TheClassicMenuForExcel2007.Connect子项中的LoadBehavior值改为0（16进制）。
	};	
	</script>
</body>
</html>